package com.xhs.main.controller.rmt;

import com.xhs.main.entity.result.LayuiResponseResult;
import com.xhs.main.entity.rmt.RmtPurchasingApply;
import com.xhs.main.entity.rmt.RmtPurchasingApplyItems;
import com.xhs.main.service.rmt.impl.RmtPurchasingApplyServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @author ZS
 * @create 2020-10-20-12:01
 */
@RestController
public class RmtPurchasingApplyController {
    @Autowired
    RmtPurchasingApplyServiceImpl rmtPurchasingApplyService;

    @ResponseBody
    @RequestMapping("/addPurchasingApply")
    public LayuiResponseResult addPurchasingApply(RmtPurchasingApply rmtPurchasingApply, RmtPurchasingApplyItems rmtPurchasingApplyItems) {
        System.out.println("add");
        rmtPurchasingApplyItems.setRmtPaiId(UUID.randomUUID().toString());
        rmtPurchasingApplyItems.setRmtPurchasingApply(rmtPurchasingApply);
        rmtPurchasingApplyItems.setRmtPaiStatus("未采购");

        List<RmtPurchasingApplyItems> rmtPurchasingApplyItemsList = new ArrayList<>();
        rmtPurchasingApply.setRmtPId(UUID.randomUUID().toString());
        rmtPurchasingApplyItemsList.add(rmtPurchasingApplyItems);
        rmtPurchasingApply.setRmtPurchasingApplyItems(rmtPurchasingApplyItemsList);
        rmtPurchasingApplyService.addPurchasingApply(rmtPurchasingApply);

        LayuiResponseResult layuiResponseResult = new LayuiResponseResult();
        layuiResponseResult.setCode(0);
        return layuiResponseResult;
    }

    @ResponseBody
    @RequestMapping("/purchasingapply")
    public LayuiResponseResult showAllPurchasingApply() {
        LayuiResponseResult responseResult = new LayuiResponseResult();
        List<RmtPurchasingApply> rmtPurchasingApplies = rmtPurchasingApplyService.selectAllPurchasingApply();
        responseResult.setCode(0);
        responseResult.setData(rmtPurchasingApplies);
        responseResult.setMsg("");
        return responseResult;
    }

    @ResponseBody
    @RequestMapping("/purchasingapplyitems")
    public LayuiResponseResult showAllPurchasingApplyItems() {
        LayuiResponseResult layuiResponseResult = new LayuiResponseResult();
        List<RmtPurchasingApplyItems> rmtPurchasingApplyItemsList = rmtPurchasingApplyService.selectAllPurchasingApplyItems();
        layuiResponseResult.setData(rmtPurchasingApplyItemsList);
        layuiResponseResult.setCode(0);
        layuiResponseResult.setMsg("");
        return layuiResponseResult;
    }
}
